//
//  recordViewController.m
//  MoneyLog
//
//  Created by Max on 11-5-8.
//  Copyright 2011年 wicresoft. All rights reserved.
//

#import "RecordViewController.h"
#import "TextFieldViewController.h"
#import "TextViewController.h"
#import "DatePickerViewController.h"
#import "KindManagerViewController.h"
#import "AccountManageViewController.h"
#import "RemarkViewController.h"
#import "GlobalDef.h"
#import "RecordWrapper.h"
#import "KindWrapper.h"
#import "AccountWrapper.h"

#import "SQLiteHelper.h"

@implementation RecordViewController
@synthesize titleString;
@synthesize record;
@synthesize kind;
@synthesize viewMode;
@synthesize kindManagerController;
@synthesize remarkController;

@synthesize actionSheet;
@synthesize pickerDataSource;
@synthesize accoutPickerView;

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [titleString release];
    [record release];
    [kind release];
    [kindManagerController release];
    [remarkController release];
    [moneyText release];
    
    [actionSheet release];
    [pickerDataSource release];
    [accoutPickerView release];
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    // 返回按钮
    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelAction)];
    self.navigationItem.leftBarButtonItem = backButton;
    [backButton release]; 	
    
    UIBarButtonItem *saveItem = [[UIBarButtonItem alloc] 
                                 initWithBarButtonSystemItem:UIBarButtonSystemItemDone
                                 target:self
                                 action:@selector(saveAction:)];
	self.navigationItem.rightBarButtonItem = saveItem;
	[saveItem release];    

    self.title=titleString;
    if (record ==nil) {
        record =[[RecordWrapper alloc] init];
    }
    
    kind = [[KindWrapper alloc] init];
    self.kind.id = record.kindId;
    self.kind.type = record.type;
    self.kind.kindName = record.kind;
    self.kind.subKindName = record.subKind;
    
    kindManagerController = [[KindManagerViewController alloc] init];
    kindManagerController.kind = self.kind;
    
    remarkController = [[RemarkViewController alloc] init];
    remarkController.view.tag = kRemarkViewController;
    remarkController.coordinate = kCLLocationCoordinate2DInvalid;
    remarkController.recordImageView.image=[UIImage imageWithData:record.imageData];
    remarkController.textView.text =record.remark;
    
    moneyText = [[UITextField alloc] initWithFrame:CGRectMake(100,10,180, 27)];
    moneyText.placeholder = NSLocalizedString(@"record_view_controller_money_placeholder", @"金额");
    moneyText.borderStyle = UITextBorderStyleNone;
    moneyText.textColor = [UIColor blackColor];
    moneyText.font = [UIFont systemFontOfSize:17.0]; 
    moneyText.backgroundColor = [UIColor whiteColor];
    moneyText.autocorrectionType = UITextAutocorrectionTypeNo;	 
    moneyText.keyboardType = UIKeyboardTypeNumberPad;	 
    moneyText.returnKeyType = UIReturnKeyDefault;
    moneyText.clearButtonMode = UITextFieldViewModeWhileEditing;	
    
    moneyText.text = (record.money ==0) ? @"" :[NSString stringWithFormat:@"%.2f",record.money];
    moneyText.delegate = self;	                      
   
    
    pickerDataSource= [[NSMutableArray alloc] initWithCapacity:1];
    //ActionSheet
    actionSheet = [[UIActionSheet alloc] 
                   initWithTitle:@""
                   delegate:self 
                   cancelButtonTitle:nil 
                   destructiveButtonTitle:nil
                   otherButtonTitles:nil]; 
	actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
    
    //PickerView
    accoutPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0, 44.0, 0.0, 0.0)];
    accoutPickerView.showsSelectionIndicator = YES;						 
    accoutPickerView.delegate = self;
    accoutPickerView.dataSource = self; 
    accoutPickerView.showsSelectionIndicator = YES;
    accoutPickerView.tag=kAccountPickerView;
    
    //default value
    if (self.viewMode==0) {
        [moneyText becomeFirstResponder]; 
        
        NSMutableArray *array = [g_Database getAccountArray:@""];
        record.account = [[array objectAtIndex:0] name];
        
        record.date =[NSDate new];
        NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init];
        [dateFormatter setTimeStyle:kCFDateFormatterFullStyle];
        [dateFormatter setDateStyle:kCFDateFormatterFullStyle];
        record.datetime=[dateFormatter stringFromDate:record.date]; 
        [dateFormatter release];
    }
    else {
        self.navigationItem.leftBarButtonItem=nil;
    }
    
    //self.navigationController.toolbarHidden = YES;
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    self.navigationController.toolbarHidden = YES;
    if (kindManagerController.kind != nil ) 
    {
        self.kind = kindManagerController.kind; 
    }
    record.remark =remarkController.textView.text;
    
    CLLocationCoordinate2D  coordinate;
    coordinate.latitude = remarkController.coordinate.latitude;
    coordinate.longitude = remarkController.coordinate.longitude;
    
    if (CLLocationCoordinate2DIsValid(coordinate)) {
        record.latitude = remarkController.coordinate.latitude;
        record.longitude = remarkController.coordinate.longitude;
    }
    
    record.imageData = UIImageJPEGRepresentation(remarkController.recordImageView.image,0);
    
    [self.tableView reloadData];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [moneyText resignFirstResponder];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    //#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    //#warning Incomplete method implementation.
    // Return the number of rows in the section.
    // Only one row for each section
	return 5;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
	return 0.0;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return [RecordViewController titleForSection:section];
}

- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
    NSString *title = nil;
	
	return title;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *kBasicCellIdentifier = @"BasicCell";
	
	UITableViewCell *cell = nil;	
				
    cell = [tableView dequeueReusableCellWithIdentifier:kBasicCellIdentifier];
    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kBasicCellIdentifier] autorelease];
    }
        
    switch (indexPath.row) {
        case kMoneyRow:
        {
            cell.textLabel.text = NSLocalizedString(@"record_view_controller_money", @"金额"); 
            [cell.contentView addSubview:moneyText];
            
            break;
        }
        case kKindRow:
        {
            cell.textLabel.text = NSLocalizedString(@"record_view_controller_kind", @"类别");
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
            
            for (UIView *view in [cell.contentView subviews]) {
                if (view.tag == kKindRow) {
                    [view removeFromSuperview];
                }
            }
            
            UILabel *control=[[UILabel alloc] initWithFrame:CGRectMake(100, 8, 80, 27)];
            [control setFont:[UIFont  fontWithName:@"Helvetica-Oblique"  size:15]];
            control.text=kind.kindName;
            control.tag = kKindRow;
            [cell.contentView addSubview:control];
            [control release];

            break;
        } 
        case kDateTimeRow:
        {
            cell.textLabel.text = NSLocalizedString(@"record_view_controller_datetime", @"时间");
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
            
            for (UIView *view in [cell.contentView subviews]) {
                if (view.tag == kDateTimeRow) {
                    [view removeFromSuperview];
                }
            }
            
            UILabel *control=[[UILabel alloc] initWithFrame:CGRectMake(100, 8,180, 30)];
            [control setFont:[UIFont  fontWithName:@"Helvetica-Oblique"  size:15]];
            NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
            [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
            control.text=[dateFormatter stringFromDate:record.date];
            control.tag = kDateTimeRow;
            [cell.contentView addSubview:control];
            [control release];
            
            [dateFormatter release];
            break;
        }
        case kAccountRow:
        {
            cell.textLabel.text = NSLocalizedString(@"record_view_controller_account", @"帐户");
            cell.accessoryType = UITableViewCellAccessoryNone; 
            
            for (UIView *view in [cell.contentView subviews]) {
                if (view.tag == kAccountRow) {
                    [view removeFromSuperview];
                }
            }
            
            UILabel *control=[[UILabel alloc] initWithFrame:CGRectMake(100, 8, 80, 27)];
            [control setFont:[UIFont  fontWithName:@"Helvetica-Oblique"  size:15]];
            control.text= record.account;
            control.tag = kAccountRow;
            [cell.contentView addSubview:control];
            [control release];
            
            break;
        } 
        case kRemarkRow: 
        {
            cell.textLabel.text = NSLocalizedString(@"record_view_controller_remark", @"备注");
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
            
            if ([record.remark length] != 0) {
                UIImageView *textImageView= [[UIImageView alloc] initWithFrame:CGRectMake(100, 8, 23, 19)];
                textImageView.image = [UIImage imageNamed:@"Icon-text.png"];
                textImageView.tag = 0xFF001;
                [cell.contentView addSubview:textImageView];
                [textImageView release];
            }
            else {
                for (UIView *view in [cell.contentView subviews]) {
                    if (view.tag == 0xFF001) {
                        [view removeFromSuperview];
                    }
                }
            }
            
            CLLocationCoordinate2D  coordinate;
            coordinate.latitude = record.latitude;
            coordinate.longitude = record.longitude;
            if (CLLocationCoordinate2DIsValid(coordinate)) {
                UIImageView *locationImageView= [[UIImageView alloc] initWithFrame:CGRectMake(140, 8, 23, 19)];
                locationImageView.image = [UIImage imageNamed:@"icon_location_2.png"];
                locationImageView.tag = 0xFF002;
                [cell.contentView addSubview:locationImageView];
                [locationImageView release];
            }
            else {
                for (UIView *view in [cell.contentView subviews]) {
                    if (view.tag == 0xFF002) {
                        [view removeFromSuperview];
                    }
                }
            }
            
            if (record.imageData) {
                UIImageView *imageView= [[UIImageView alloc] initWithFrame:CGRectMake(180, 8, 23, 19)];
                imageView.image = [UIImage imageNamed:@"Icon_photo_1.png"];
                imageView.tag = 0xFF003;
                [cell.contentView addSubview:imageView];
                [imageView release];
            }
            else {
                for (UIView *view in [cell.contentView subviews]) {
                    if (view.tag == 0xFF003) {
                        [view removeFromSuperview];
                    }
                }
            }

            
            break;
        } 
        default:
            break;
    }
    
	return cell;
}

/*
 // Override to support conditional editing of the table view.
 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
 {
 // Return NO if you do not want the specified item to be editable.
 return YES;
 }
 */

/*
 // Override to support editing the table view.
 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
 {
 if (editingStyle == UITableViewCellEditingStyleDelete) {
 // Delete the row from the data source
 [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
 }   
 else if (editingStyle == UITableViewCellEditingStyleInsert) {
 // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
 }   
 }
 */

/*
 // Override to support rearranging the table view.
 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
 {
 }
 */

/*
 // Override to support conditional rearranging of the table view.
 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
 {
 // Return NO if you do not want the item to be re-orderable.
 return YES;
 }
 */

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [moneyText resignFirstResponder];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    switch (indexPath.row) {
        case kKindRow:
        { 
            NSLog(@"kind=%@",self.kind);
            kindManagerController.view.tag = kKindViewController;
            kindManagerController.kind = self.kind;
            [self.navigationController pushViewController:kindManagerController animated:YES]; 
            break;
        } 
        case kDateTimeRow:
        { 		
            DatePickerViewController *viewController=[[DatePickerViewController alloc] initWithStyle:UITableViewStyleGrouped];
            viewController.titleString=@"选择时间";
            viewController.view.tag = kDateTimeViewController;
            viewController.myViewDelegate = self;
            if (record.date !=nil) {
                [viewController.datePicker setDate:record.date];
            }
            else {
                [viewController.datePicker setDate:[NSDate date]];
            }
            [self.navigationController pushViewController:viewController animated:YES]; 
            
            break;
        }
        case kAccountRow:
        { 	
            NSMutableArray *array = [g_Database getAccountArray:@""];
            [self.pickerDataSource removeAllObjects];
            [self.pickerDataSource addObject:array];
            [array release];
            
            [self.accoutPickerView reloadAllComponents];

            //工具栏
            CGRect appRect = [[UIScreen mainScreen] applicationFrame];
            UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, appRect.size.width, 44)];
            toolBar.barStyle = UIBarStyleBlack;
            toolBar.translucent =YES;
            [toolBar sizeToFit];
            
            //add
            UIBarButtonItem *addButton =[[UIBarButtonItem alloc] 
                                         initWithBarButtonSystemItem:UIBarButtonSystemItemAdd 
                                         target:self 
                                         action:@selector(accountAddAction)];
            addButton.style = UIBarButtonItemStyleBordered;
        
            //标题
            UIBarButtonItem *titleButton = [[UIBarButtonItem alloc] init];
            titleButton.style = UIBarButtonItemStylePlain;
            titleButton.title = @"选择帐户";
                
            //分隔
            UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] 
                                          initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace 
                                          target:self action:nil];
            //确定按钮
            UIBarButtonItem *buttonDone = [[UIBarButtonItem alloc] 
                                           initWithBarButtonSystemItem:UIBarButtonSystemItemDone 
                                           target:self 
                                           action:@selector(pickerDone)];
            
             NSMutableArray *barItems = [NSMutableArray arrayWithObjects:
                                         addButton,
                                         flexSpace,
                                         titleButton,
                                         flexSpace,
                                         buttonDone,nil]; 
            [toolBar setItems:barItems animated:YES];
            [addButton release];
            [titleButton release];
            [flexSpace release];
            [buttonDone release];
            
            [actionSheet addSubview:toolBar];
            [actionSheet addSubview:accoutPickerView];    
            [actionSheet showInView:[UIApplication sharedApplication].keyWindow];
            [actionSheet setBounds:CGRectMake(0, 0, appRect.size.width, appRect.size.height)];
            
            [toolBar release];

            break;
        } 
        case kRemarkRow:
        {
            remarkController.textView.text = record.remark;
            
            CLLocationCoordinate2D coordinate;
            coordinate.latitude = record.latitude;
            coordinate.longitude = record.longitude;
            remarkController.coordinate = coordinate;
            remarkController.recordImageView.image=[UIImage imageWithData:record.imageData];
            
            [self.navigationController pushViewController:remarkController animated:YES];
            
            break;
        }
       
        default:
            break;
    }
}

#pragma mark - * UITextFieldDelegate

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
	// the user pressed the "Done" button, so dismiss the keyboard
	[textField resignFirstResponder]; 
    record.money=[textField.text floatValue];
	return YES;
}

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
    [textField resignFirstResponder];
    if ([textField.text length] != 0) {
        record.money = [textField.text floatValue];
    }
    
    return YES;
}

#pragma mark - * MyView delegate

-(void) myView:(UIView *)myView id:(id)sender{
    if( myView.tag == kKindViewController){
        NSArray *objects=[sender componentsSeparatedByString:@"||"];
        record.kind= [objects objectAtIndex:0]; 
        record.kindId= [[objects objectAtIndex:1] intValue];
        
        record.subKind=@"";
    }
    else if( myView.tag == kDateTimeViewController){
        record.date = sender;
        
        NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init];
        [dateFormatter setTimeStyle:kCFDateFormatterFullStyle];
        [dateFormatter setDateStyle:kCFDateFormatterFullStyle];
        record.datetime=[dateFormatter stringFromDate:record.date]; 
        [dateFormatter release];
    }
    else if( myView.tag == kRemarkViewController){
        record.remark = sender;
    }
        
    [self.tableView reloadData];
}

#pragma mark - * UIPickerViewDelegate

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
	if (pickerView.tag == kAccountPickerView)
	{
	}
}

#pragma mark - * UIPickerViewDataSource

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
	NSString *content=@"";
	
	// note: custom picker doesn't care about titles, it uses custom views
	NSMutableArray *array =[self.pickerDataSource objectAtIndex:component];
    switch (pickerView.tag) {
        case kAccountPickerView:
        {
            AccountWrapper *account = [array objectAtIndex:row];
            content = account.name;
            break;
        }
        default:
            break;
    }
    
	return content;
}

- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
{
	CGFloat componentWidth = 0.0;
    
    if ([pickerDataSource count]==1) {
        componentWidth = 280.0;
    }
    else
    {
        if (component == 0)
            componentWidth = 140.0;
        else
        {
            componentWidth = 140.0;
        }
    }
	
	return componentWidth;
}

- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
	return 40.0;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    NSMutableArray *array =[self.pickerDataSource objectAtIndex:component];
    
	return [array count]; 
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
	return [pickerDataSource count];
}

#pragma mark - * ActionSheet delegate method.

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    // the user clicked one of the OK/Cancel buttons
    if (buttonIndex == 0)
    {
        exit(0);
    }
}

#pragma mark - * Actions

-(IBAction)cancelAction {
    
    if (viewMode == 0) {
        [self.parentViewController dismissModalViewControllerAnimated:YES];
    }
    else {
        [self.navigationController popViewControllerAnimated:YES];
    }
    
}

- (void)saveAction:(id)sender
{
    if (viewMode == 0) 
    {
        record.type=self.kind.type;
        record.money_kind=@"RMB";
        record.kind = self.kind.kindName;
        record.subKind = self.kind.subKindName == nil ? @"" : kind.subKindName;
        
        if (record.money == 0) {
            record.money=[moneyText.text floatValue];
        }
        
        if ([record.kind length]==0 ||[record.datetime length]==0 || record.money == 0) 
        {
            return;
        }
        
        if ( ![g_Database recordAdd:record] ) {
            UIAlertView * alertView = [[UIAlertView alloc] 
                                       initWithTitle:@"提示" 
                                       message:@"添加记录失败了！"
                                       delegate:nil 
                                       cancelButtonTitle:@"确定" 
                                       otherButtonTitles:nil];
            [alertView show];
            [alertView release];
        }
        
        //更新类型使用次数
        self.kind.useTimes++;
        if ( ![g_Database updateKind:self.kind] ) {
            UIAlertView * alertView = [[UIAlertView alloc] 
                                       initWithTitle:@"提示" 
                                       message:@"更新类型失败了！"
                                       delegate:nil 
                                       cancelButtonTitle:@"确定" 
                                       otherButtonTitles:nil];
            [alertView show];
            [alertView release];
        }
        
        [self.parentViewController dismissModalViewControllerAnimated:YES];
    }
    else if(viewMode ==1)
    {
        record.type=self.kind.type;
        record.money_kind=@"RMB";
        record.kind = self.kind.kindName;
        record.subKind = self.kind.subKindName == nil ? @"" : kind.subKindName;
        
        if (record.money != [moneyText.text floatValue]) {
            record.money=[moneyText.text floatValue];
        }
        
        if ([record.kind length]==0 ||[record.datetime length]==0 || record.money == 0) 
        {
            return;
        }
        
        if ( ![g_Database recordUpdate:record] ) {
            UIAlertView * alertView = [[UIAlertView alloc] 
                                       initWithTitle:@"提示" 
                                       message:@"更新记录失败了！"
                                       delegate:nil 
                                       cancelButtonTitle:@"确定" 
                                       otherButtonTitles:nil];
            [alertView show];
            [alertView release];
        }
        
        [self.navigationController popViewControllerAnimated:YES];
    }
}

-(void)pickerDone{
    NSMutableArray *array = [self.pickerDataSource objectAtIndex:0];
    AccountWrapper *account = [array objectAtIndex:[accoutPickerView selectedRowInComponent:0]];
    record.account = account.name;
    
    [actionSheet dismissWithClickedButtonIndex:0 animated:YES];
    [self.tableView reloadData];
}

-(void)accountAddAction
{
    [actionSheet dismissWithClickedButtonIndex:0 animated:YES];
    
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] 
                                 initWithTitle:@"返回" 
                                 style:UIBarButtonItemStyleBordered 
                                 target:nil action:nil];
    
    AccountManageViewController *controller = [[AccountManageViewController alloc] init];
    controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    controller.displayType = 0;
    UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:controller];
    navigation.navigationItem.backBarButtonItem = backItem;
    
    [self.navigationController presentModalViewController:navigation animated:YES];
    [controller release];
    [navigation release];
    [backItem release];
}

#pragma mark - * 静态方法

+ (NSString *)titleForSection:(NSInteger)section
{
    switch (section)
    {
        case kBasicSection: return NSLocalizedString(@"record_view_controller_section", @"记录明细");
        case kExtendSection: return NSLocalizedString(@"add_expense_extend", @"扩展信息");
    }
    return nil;
}


@end
